//
//  NetWorkManager.m
//  JZRJAPPT
//
//  Created by mac on 16/5/9.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "NetWorkManager.h"
#import "AFNetworking.h"
#import "Networkrequest.h"

@implementation NetWorkManager


//+ (void)getUrl:(NSString *)url paramdic:(NSDictionary *)param success:(void (^)(id))success error:(void (^)(id))fail{
//
//    AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
//
//    sessionManager.requestSerializer = [AFHTTPRequestSerializer serializer];
//    sessionManager.responseSerializer = [AFJSONResponseSerializer serializer];
//    sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html",@"image/jpeg",@"text/plain",nil];
//    // 设置访问超时时间 （系统默认是60）
//    sessionManager.requestSerializer.timeoutInterval = 30;
//    [sessionManager GET:url parameters:param progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        if (success) {
//            success(responseObject);
//        }
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        if (fail) {
//            fail(error);
//        }
//    }];
//}

+ (void)getUrl:(NSString *)url paramdic:(NSDictionary *)param success:(void (^)(id))success error:(void (^)(id))fail{
    
    AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
    
    sessionManager.requestSerializer = [AFHTTPRequestSerializer serializer];
    sessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
    sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html",@"image/jpeg",@"text/plain",nil];
    // 设置访问超时时间 （系统默认是60）
    sessionManager.requestSerializer.timeoutInterval = 30;
    [sessionManager GET:url parameters:param progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (success) {
            NSLog(@"%@", task.response);
            
            
            success(responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (fail) {
            fail(error);
        }
    }];
}

+ (void)postUrl:(NSString *)url paramdic:(NSDictionary *)param success:(void (^)(id))success error:(void (^)(id))fail{
    
    AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
    sessionManager.requestSerializer = [AFHTTPRequestSerializer serializer];
    sessionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
    sessionManager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html",@"image/jpeg",@"text/plain",nil];
    // 设置访问超时时间 （系统默认是60）
    sessionManager.requestSerializer.timeoutInterval = 30;
    
        NSString *urlStr = [NSString stringWithFormat:@"%@%@",BaseUrl,url];
    [sessionManager POST:urlStr parameters:param progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (success) {
            NSLog(@"%@", task.response);
            success(responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (fail) {
            fail(error);
        }
    }];
}
//+(NSString *)getUniqueStrByUUID {
//    NSString * currentDeviceUUIDStr = [SAMKeychain passwordForService:@" " account:@"GreatChefUUID"];
//    if (currentDeviceUUIDStr == nil || [currentDeviceUUIDStr isEqualToString:@""])
//    {
//        NSUUID * currentDeviceUUID  = [UIDevice currentDevice].identifierForVendor;
//        currentDeviceUUIDStr = currentDeviceUUID.UUIDString;
//        currentDeviceUUIDStr = [currentDeviceUUIDStr stringByReplacingOccurrencesOfString:@"-" withString:@""];
//        currentDeviceUUIDStr = [currentDeviceUUIDStr lowercaseString];
//        [SAMKeychain setPassword: currentDeviceUUIDStr forService:@" " account:@"GreatChefUUID"];
//    }
//    return currentDeviceUUIDStr;
//}

@end
